package com.example.task4.controller;

import java.io.*;
import java.util.List;

import com.example.task4.dao.CakeDao;
import com.example.task4.domain.Cake;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
//配置启动时加载
@WebServlet(urlPatterns = "/init",loadOnStartup = 1)
public class InitServlet extends HttpServlet {
    List<Cake> cakeList;
    public void init() {
        //创建CakeDao类的对象
            CakeDao dao=new CakeDao();
        //获取所有蛋糕信息，并存入cakeList集合中
            cakeList=dao.listCakes();

        //将cakeList存入application中
        getServletConfig().getServletContext().setAttribute("cakes",cakeList);
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.sendRedirect("index.jsp");
    }

    public void destroy() {
    }
}